// 工单管理
<template>
  <div class="problemList" id="userBig">
    <div class="problem-R noControlPanel">
      <el-tabs class="scorllFixed" v-model="activeName" @tab-click="handleClick">
        <el-tab-pane :label="item.name" :name="item.path" v-for="item in jurisdiction" :key="item.path">
          <router-view v-if="activeName === item.path"></router-view>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
import { setUrl } from '@/utils/getUrl.js'
import { getAuthority } from '@/assets/js/getAuthority.js'
// import { globalBus } from '@/assets/js/globalBus'
// import { pinT } from '@/utils/allUrl.js'
// import { startLoading } from '@/utils/loading.js'
export default {
  data: function () {
    return {
      activeName: 'workOrderList',
      jurisdiction: [
        // {
        //   title: '工单列表',
        //   url: 'workOrderList'
        // }
        // {
        //   title: '工单字典管理',
        //   url: 'workdictionaries'
        // }
      ],
    }
  },
  watch: {
    jurisdiction: {
      deep: true,
      handler(newVal, oldVal) {
        // console.log(newVal, oldVal)
        this.jurisdiction = newVal // 保存列表
        this.activeName = this.$route.name
        this.$router.push(this.$route.path)
      },
    },
    // 监听url中的hash值的变化
    $route(to, from) {
      const hashUrl = window.location.hash.substr(2)
      if (hashUrl.startsWith('workOrderList')) {
        this.activeName = 'workOrderList'
      } else if (hashUrl.startsWith('workdictionaries')) {
        this.activeName = 'workdictionaries'
      }
    },
  },
  created() {
    getAuthority(this, 'workorder') // 获取权限
  },
  mounted() {
    // 利用事件线  监听一个事件
    // globalBus.$on('toggleWorkOrderTarget', this.toggleWorkOrder)
  },
  destroyed: function () {
    // 默认
    setUrl('workorder', '')
  },
  methods: {
    // 刷新右侧需要调用的函数
    getChildRefresh() {
      getAuthority(this, 'workorder') // 获取权限
    },
    handleClick(tab, event) {
      // 防止一直加载动画
      // if (window.location.hash.substr(2) !== tab.name) {
      //   startLoading(document.getElementById('userBig'))
      // }
      setUrl('workorder', tab.name)
      if (tab.name === 'workOrderList') {
        this.$router.push('/workOrderList')
      } else if (tab.name === 'workdictionaries') {
        this.$router.push('/workdictionaries')
      }
    },

    // async toggleWorkOrder(params) {
    //   if (params) {
    //     var accessName = this.$route.name
    //     const params = new URLSearchParams()
    //     params.append('QXFWLJ', accessName)
    //     const { data: res } = await this.$http.post(`${pinT}quanXian/selectQuanXian`, params)
    //     if (res.code === '0000') {
    //       this.sonMessage(res.data[0])
    //     }
    //   }
    // },

    // sonMessage(val) {
    //   this.$emit('getSonMessageHome', val)
    // },
  },
  beforeDestroy() {
    // console.log('组件销毁前需要解绑事件。否则会出现重复触发事件的问题')
    // globalBus.$off('toggleWorkOrderTarget', this.toggleWorkOrder)
  },
}
</script>

<style lang="scss" scoped></style>
